package com.spring.schooltest.scheduling;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入进程总数: ");
        // 进程总数量
        int processNum = sc.nextInt();

        Scanner sc1 = new Scanner(System.in);
        System.out.println("请输入进程名称, 每个名称用一个空格分开: ");
        String names = sc1.nextLine();

        // 存储进程名字分割后的数组
        String[] nameList = names.split(" ");

        // 输入每个进程需要运行的时间，以空格分开
        Scanner sc2 = new Scanner(System.in);
        System.out.println("请输入每个进程需要运行的时间，以空格分开: ");
        String processRunTimeStr = sc2.nextLine();

        // 存储每个时间的数组
        String[] processRunTimeList = processRunTimeStr.split(" ");

        // 以下是将String类型的运行时间转换成int类型
        // 进程运行时间的个数
        int proRunTimeLength = processRunTimeList.length;

        // 每个进程需要运行的时间
        int[] proRunTimeNumList = new int[proRunTimeLength];
        for (int i = 0; i < proRunTimeLength; i++) {
            proRunTimeNumList[i] = Integer.parseInt(processRunTimeList[i]);
        }

        // 输入每个进程的优先级
        System.out.println("请输入每个进程的优先级，每个数用空格分开，优先级不能重复: ");
        Scanner sc3 = new Scanner(System.in);
        String priorityStr = sc3.nextLine();
        String[] priorityList = priorityStr.split(" ");

        // 存储所有已就绪进程对象的集合
        List<MyProcess> processList = new ArrayList<>();
        for (int i = 0; i < processNum; i++) {
            String name = nameList[i];
            int serveTime = proRunTimeNumList[i];
            int priority = Integer.parseInt(priorityList[i]);

            MyProcess process = new MyProcess();
            process.setName(name);
            process.setServeTime(serveTime);
            process.setPriority(priority);
            // 把设置好的进程放入list中
            processList.add(process);
        }

        Simulate simulate = new Simulate();
        simulate.simulateCPU(processList);
    }
}
